package com.sky.mapper;

import com.sky.anno.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 菜品的条件分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    List<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据菜品id删除菜品
     *
     * @param dishId
     */
    @Delete("delete from dish where id = #{dishId}")
    void deleteDishById(Long dishId);

    /**
     * 根据菜品id查询该菜品的状态
     *
     * @param dishId
     * @return
     */
    @Select("select status from dish where id = #{dishId}")
    Integer selectStatusById(Long dishId);

    /**
     * 根据id查询菜品用于修改时的数据回显
     *
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish findDishById(Long id);

    /**
     * 根据id修改dish表中的菜品数据
     *
     * @param dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据name查询菜品
     *
     * @param name
     * @return
     */
    List<DishVO> selectDishByNameAndCategoryId(String name,Long categoryId);

    /**
     * 菜品起售、停售
     *
     * @param status
     * @param id
     */
    @Update("update dish set status = #{status} where id = #{id}")
    void updateDishStatus(Integer status, Long id);


    List<Dish> list(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
